package com.lagou.edu.demo.config;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;


@Component
public class LocalEventListener implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    private DefaultListableBeanFactory defaultListableBeanFactory;

    private boolean doFist = true;

    @Autowired
    private HikariDataSource hikariDataSource;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {

        HikariDataSource bean = defaultListableBeanFactory.getBean(HikariDataSource.class);
        if (doFist) {
            if (bean != null) {
                doFist = false;
            }
        }
    }
}